From 6803d93d38eb7f1cf09b89eeaf0cb414ab001d15 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 3 Jan 2005 19:16:20 +0000 Subject: [PATCH] Some updates for the drawing section. (#161414, Robert Ancell) 2005-01-03 Matthias Clasen * docs/tutorial/gtk-tut.sgml: Some updates for the drawing section. (#161414, Robert Ancell) --- ChangeLog | 3 ++ ChangeLog.pre-2-10 | 3 ++ ChangeLog.pre-2-6 | 3 ++ ChangeLog.pre-2-8 | 3 ++ docs/tutorial/gtk-tut.sgml | 56 ++++++++++++++++++++++++-------------- 5 files changed, 47 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index 28a555ed09..b596c901f5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2005-01-03 Matthias Clasen + * docs/tutorial/gtk-tut.sgml: Some updates for the drawing + section. (#161414, Robert Ancell) + * docs/tutorial/gtk-tut.sgml: Make it build. * gtk/gtkdialog.c (gtk_dialog_run): Some clarification diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 28a555ed09..b596c901f5 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,5 +1,8 @@ 2005-01-03 Matthias Clasen + * docs/tutorial/gtk-tut.sgml: Some updates for the drawing + section. (#161414, Robert Ancell) + * docs/tutorial/gtk-tut.sgml: Make it build. * gtk/gtkdialog.c (gtk_dialog_run): Some clarification diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 28a555ed09..b596c901f5 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,5 +1,8 @@ 2005-01-03 Matthias Clasen + * docs/tutorial/gtk-tut.sgml: Some updates for the drawing + section. (#161414, Robert Ancell) + * docs/tutorial/gtk-tut.sgml: Make it build. * gtk/gtkdialog.c (gtk_dialog_run): Some clarification diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 28a555ed09..b596c901f5 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,5 +1,8 @@ 2005-01-03 Matthias Clasen + * docs/tutorial/gtk-tut.sgml: Some updates for the drawing + section. (#161414, Robert Ancell) + * docs/tutorial/gtk-tut.sgml: Make it build. * gtk/gtkdialog.c (gtk_dialog_run): Some clarification diff --git a/docs/tutorial/gtk-tut.sgml b/docs/tutorial/gtk-tut.sgml index 8ee241f2fc..6caf78ab57 100755 --- a/docs/tutorial/gtk-tut.sgml +++ b/docs/tutorial/gtk-tut.sgml @@ -12772,7 +12772,7 @@ static gboolean configure_event( GtkWidget *widget, GdkEventConfigure *event ) { if (pixmap) - gdk_pixmap_unref(pixmap); + g_object_unref(pixmap); pixmap = gdk_pixmap_new(widget->window, widget->allocation.width, @@ -12801,12 +12801,12 @@ to redraw by using the event->area field of the exposure event): static gboolean expose_event( GtkWidget *widget, GdkEventExpose *event ) { - gdk_draw_pixmap(widget->window, - widget->style->fg_gc[GTK_WIDGET_STATE (widget)], - pixmap, - event->area.x, event->area.y, - event->area.x, event->area.y, - event->area.width, event->area.height); + gdk_draw_drawable(widget->window, + widget->style->fg_gc[GTK_WIDGET_STATE (widget)], + pixmap, + event->area.x, event->area.y, + event->area.x, event->area.y, + event->area.width, event->area.height); return FALSE; } @@ -12818,28 +12818,36 @@ large number of calls in GTK's GDK library for drawing on drawables. A drawable is simply something that can be drawn upon. It can be a window, a pixmap, or a bitmap (a black and white image). We've already seen two such calls above, -gdk_draw_rectangle() and gdk_draw_pixmap(). The +gdk_draw_rectangle() and gdk_draw_drawable(). The complete list is: +gdk_draw_point () gdk_draw_line () gdk_draw_rectangle () gdk_draw_arc () gdk_draw_polygon () -gdk_draw_string () -gdk_draw_text () gdk_draw_pixmap () gdk_draw_bitmap () gdk_draw_image () gdk_draw_points () gdk_draw_segments () +gdk_draw_lines () +gdk_draw_pixbuf () +gdk_draw_glyphs () +gdk_draw_layout_line () +gdk_draw_layout () +gdk_draw_layout_line_with_colors () +gdk_draw_layout_with_colors () +gdk_draw_glyphs_transformed () +gdk_draw_glyphs_trapezoids () See the reference documentation or the header file -<gdk/gdk.h> for further details on these functions. +<gdk/gdkdrawable.h> for further details on these functions. These functions all share the same first two arguments. The first argument is the drawable to draw upon, the second argument is a -graphics context (GC). +graphics context (GC). A graphics context encapsulates information about things such as foreground and background color and line width. GDK has a full set of @@ -12887,11 +12895,13 @@ draw_brush (GtkWidget *widget, gdouble x, gdouble y) update_rect.width = 10; update_rect.height = 10; gdk_draw_rectangle (pixmap, - widget->style->black_gc, - TRUE, + widget->style->black_gc, + TRUE, update_rect.x, update_rect.y, update_rect.width, update_rect.height); - gtk_widget_draw (widget, &update_rect); + gtk_widget_queue_draw_area (widget, + update_rect.x, update_rect.y, + update_rect.width, update_rect.height); } @@ -12899,14 +12909,18 @@ draw_brush (GtkWidget *widget, gdouble x, gdouble y) we call the function: -void gtk_widget_draw (GtkWidget *widget, - GdkRectangle *area); +void gtk_widget_queue_draw_area (GtkWidget *widget, + gint x, + gint y, + gint width, + gint height) -which notifies X that the area given by the area parameter +which notifies X that the area given by the x, +y, width and height parameters needs to be updated. X will eventually generate an expose event (possibly combining the areas passed in several calls to -gtk_widget_draw()) which will cause our expose event handler +gtk_widget_queue_draw_area()) which will cause our expose event handler to copy the relevant portions to the screen. We have now covered the entire drawing program except for a few @@ -15743,8 +15757,8 @@ static void draw_brush( GtkWidget *widget, update_rect.x, update_rect.y, update_rect.width, update_rect.height); gtk_widget_queue_draw_area (widget, - update_rect.x, update_rect.y, - update_rect.width, update_rect.height); + update_rect.x, update_rect.y, + update_rect.width, update_rect.height); } static gboolean button_press_event( GtkWidget *widget, -- 2.30.2